home *** CD-ROM | disk | FTP | other *** search
- /*
- File: WorkSpace.c
-
- Contains: QuickDraw GX to PostScript conversion code.
- File contains routines to allocate and deallocate the
- Imaging Engine workspaces.
-
- Routines include:
- PSReleaseWorkSpace
- PSSetWorkSpaceSize
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1990-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- #include <MacMemory.h>
- #include "Private.h"
- #include "IOUtilities.h"
-
- #ifdef resumeLabel
- #undef resumeLabel
- #endif
- #define resumeLabel(exception)
-
-
- /*************************************************************
- The following routines control the size of the workspace.
- The workspace is a handle that hangs off of our globals which we
- use for pointers that we must pass to gx graphics so we can get shape data.
-
- The workspace is resized to be as big as wee need it. It's size is
- set back to zero if it was bigger than the maximum persistant threshold.
- That way, outlying large requests are not left around.
-
- Additionally, when not in use, the handle is purgeable. That we we
- are not a total pig.
-
- The proper way to use the workspace is as follows:
-
- status = PSSetWorkSapceSize(hGlobals, neededSize);
- workHandle = (*hGlobals)->hWorkSpace; // Get current workspace handle
- //Do some work with the workspace, copy glyph data in etc…
- …
- …
- status = PSReleaseWorkSpace(hGlobals);
-
- Actually, there is an array of workspaces.
- This is to allow nested use of the workspace.
- This can be necessitated by recursive text face styles.
- Example: Glyph shape (which uses workspace) has a text face
- which has a style which has a pattern which has a
- shape which is a glyph or a bitmap (which uses workspace) and so on.
-
-
- ********************************************************************/
-
- //<FF>
- /***************************************************
- Routine PSSetWorkSpaceSize:
-
- Routine makes sure that our current workspace is big enough
- for whatever we need to do. Used in place of NewHandle, or NewPtr.
-
- hGlobals: Handle to our globals.
- newSize: How much space we need.
-
- ****************************************************/
- OSErr PSSetWorkSpaceSize(TIEGlobalsHdl hGlobals, long newSize)
- {
- OSErr status = noErr;
- register TIEGlobalsPtr pGlobals;
- Handle aHandle;
- long currSize;
- Handle *workSpaceArray;
-
- pGlobals = *hGlobals;
-
- require((pGlobals->workSpaceIndex < pGlobals->params.gsaveLimit), workSpaceToDeep);
-
- workSpaceArray = (Handle*)((long)pGlobals + pGlobals->offsetToWorkspace);
-
- /** Make sure handle at this level has been allocated **/
-
- if (workSpaceArray[pGlobals->workSpaceIndex] == nil) {
-
- status = PrNewHandle(&aHandle, newSize);
- nrequire(status, failed_Alloc);
-
- pGlobals = *hGlobals;
- workSpaceArray = (Handle*)((long)pGlobals + pGlobals->offsetToWorkspace);
-
- workSpaceArray[pGlobals->workSpaceIndex] = aHandle;
- pGlobals->hWorkSpace = aHandle;
-
- } else {
-
- pGlobals->hWorkSpace = workSpaceArray[pGlobals->workSpaceIndex];
- currSize = GetHandleSize(pGlobals->hWorkSpace);
-
- // Check to see if the workspace was purged, if it was allocate a new one.
- if ( *(pGlobals->hWorkSpace) == nil) {
-
- ReallocateHandle(pGlobals->hWorkSpace, newSize);
- status = MemError();
- nrequire(status, failed_Realloc);
-
- } else if (newSize > currSize) {
-
- /** First try to grow, if grow fails, dispose and try to reallocate **/
-
- status = PrSetHandleSize(pGlobals->hWorkSpace, newSize);
- if (status != noErr) {
-
- pGlobals = *hGlobals;
- (void) DisposeHandle(pGlobals->hWorkSpace);
- nrequire(status = PrNewHandle(&aHandle, newSize), failed_SetSize);
-
- (*hGlobals)->hWorkSpace = aHandle;
-
- } //end if
- nrequire(status, failed_SetSize);
-
- }//end if
-
- }//end if
-
- pGlobals = *hGlobals;
- HNoPurge(pGlobals->hWorkSpace); // Make sure it isn't purged while in use.
-
- /** Set up for next level of workspace if called recursively **/
- ++(pGlobals->workSpaceIndex);
-
-
- failed_Realloc:
- failed_SetSize:
- failed_Alloc:
- return(status);
-
- /** Will exceed gsave limit due to recursive style **/
- workSpaceToDeep:
- return(-999);
-
- }//PSSetWorkSpaceSize
-
-
-
-
-
- //<FF>
- /***************************************************
- Routine PSReleaseWorkSpace:
-
- Call this when done using the WorkSpace in a routine.
- Unlock and mark the handle purgeable so we aren't piggy.
-
- hGlobals: Handle to our globals.
-
- ****************************************************/
-
- OSErr PSReleaseWorkSpace(TIEGlobalsHdl hGlobals)
- {
- TIEGlobalsPtr pGlobals;
- OSErr status = noErr;
-
- pGlobals = *hGlobals;
-
-
- HUnlock(pGlobals->hWorkSpace); // In case client left it locked.
- HPurge(pGlobals->hWorkSpace); // Mark it purgable, we don't want to be a pig.
-
- --(pGlobals->workSpaceIndex); // Pop a workspace.
-
- failed_SetSize:
- return(status);
-
- }//PSReleaseWorkSpace
-
-